package channel

import (
	"context"

	"gitee.com/liangziyisheng/caas-platform-mc/utility/utils"
	"github.com/gogf/gf/v2/errors/gerror"

	v1 "caas-platform-payment/api/channel/v1"
	"caas-platform-payment/internal/consts"
	"caas-platform-payment/internal/dao"
	"caas-platform-payment/internal/model/do"
)

func (c *ControllerV1) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error) {
	// return nil, gerror.NewCode(gcode.CodeNotImplemented)
	in := &do.PayChannel{}
	utils.CopyStruc(*req, in)
	in.Id = req.Id
	res = &v1.UpdateRes{}
	res.Rows, err = dao.PayChannel.Ctx(ctx).Data(in).Where(dao.PayChannel.Columns().Id, in.Id).UpdateAndGetAffected()
	if err != nil {
		return nil, gerror.NewCode(consts.UpdateFailed)
	}
	return res, nil
}
